#!/usr/bin/env python
# -*- coding:UTF-8 -*-
"""
command.py
命令模式代码原型
"""
from abc import ABCMeta, abstractmethod

class Receiver(object):
    def show_a(self): return self.show_a.__name__

    def show_b(self): return self.show_b.__name__


class Command(object):
    __metaclass__ = ABCMeta

    def __init__(self, receiver): self.receiver = receiver

    @abstractmethod
    def show(self): pass


class CommandA(Command):
    def show(self): return self.receiver.show_a()

class CommandB(Command):
    def show(self): return self.receiver.show_b()


class Invoker(object):
    def __init__(self): self.commands = []

    def add(self, c): self.commands.append(c)

    def remove(self, c): self.commands.remove(c)

    def invoke(self):
        for c in self.commands:
            print(c.show())
